home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_06 / 9n06114a < prev    next >
Text File  |  1991-02-16  |  1KB  |  44 lines

  1. /*
  2.  *  cat.c: concatenate files.
  3.  *      written by Leor Zolman
  4.  *
  5.  *  usage:
  6.  *      cat [list of files]
  7.  *  Sends the contents of all specified files (or the
  8.  *  standard input, if no filenames are specified) 
  9.  *  to the standard output.
  10.  *  
  11.  *  This version is intended for DOS systems only,
  12.  *  since all *nix systems should already have it
  13.  *  as standard equipment.
  14.  */
  15.  
  16. #include <stdio.h>
  17.  
  18. main(int argc, char **argv)
  19. {
  20.     int i, c;
  21.     FILE *fp;
  22.     
  23.     if (argc == 1)  /* if no filenames supplied, read input */
  24.     {                           /* from standard input only */
  25.         while ((i = getchar()) != EOF)
  26.             putchar(i);
  27.     }
  28.     else
  29.     {
  30.         for (i = 1; i < argc; i++)
  31.         {
  32.             if ((fp = fopen(argv[i], "r")) == NULL)
  33.             {
  34.                 fprintf(stderr, "%s: can't open %s\n",
  35.                             argv[0], argv[i]);
  36.                 exit(1);
  37.             }
  38.             while ((c = getc(fp)) != EOF)
  39.                 putchar(c);
  40.         }
  41.     }
  42.     return 0;
  43. }
  44.